package com.atguigu.gmall.user.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.user.model.UserInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.user.service.UserInfoService;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户表 前端控制器
 *
 * @author atguigu
 * @since 2022-12-15
 */
@Api(tags = "用户表控制器")
@RestController
@RequestMapping("/api/user/passport")
public class PassportController {


    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户登录
     * @param loginInfo
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody UserInfo loginInfo, HttpServletRequest request){
        return userInfoService.login(loginInfo, request);
    }


    /**
     * 用户退出
     * @param token 请求头中token令牌
     * @return
     */
    @GetMapping("/logout")
    public Result logout(@RequestHeader("token") String token){
        userInfoService.logout(token);
        return Result.ok();
    }


}
